﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using ESRI.ArcGIS.SystemUI;
using PlanningGIS.Framework;
using ESRI.ArcGIS.Display;
using PlanningGIS.Engine.Controls;
using PlanningGIS.Util.Management;
using ESRI.ArcGIS.Carto;
using ESRI.ArcGIS.ADF.Connection.Local;
using System.Drawing;

namespace PlanningGIS.Draw
{    
    /// <summary>
    /// 点颜色
    /// </summary>
    public partial class DropDownMarkerColor : DropDownStyleColor, ICommand
    {
        /// <summary>
        /// 构造函数
        /// </summary>
        public DropDownMarkerColor()
        {
            this.SetStyle(ControlStyles.DoubleBuffer, true);
            InitializeComponent();
            Init();

        }
        /// <summary>
        /// 构造函数
        /// </summary>
        /// <param name="container">控件容器</param>
        public DropDownMarkerColor(IContainer container)
        {
            this.SetStyle(ControlStyles.DoubleBuffer, true);
            container.Add(this);
            InitializeComponent();
            Init();
        }

        /// <summary>
        /// 系统框架
        /// </summary>
        IApplication m_Application = null;

        /// <summary>
        /// 初始化
        /// </summary>
        private void Init()
        {
            base.InitStyle();

            string imgname2 = this.GetType().Namespace + ".Resources.PointColor.png";
            Bitmap bmp2 = new Bitmap(GetType().Assembly.GetManifestResourceStream(imgname2));
            bmp2.MakeTransparent();
            base.ImageShape = bmp2;

            base.ToolTip = "点颜色设置";
            base.SelectedColor = Color.Black;
        }


        /// <summary>
        /// 
        /// </summary>
        protected override void OnSelectColor()
        {
            base.OnSelectColor();
            (m_Application.Document as IMxDocument).set_DefaultColor(esriMxDefaultColorTypes.esriMxMarkerColor, Converter.ToRGBColor(base.SelectedColor));
            IActiveView m_ActiveView = (m_Application.Document as IMxDocument).ActiveView;
            IGraphicsContainerSelect pGraphicsContainerSelect = m_ActiveView as IGraphicsContainerSelect;
            if (pGraphicsContainerSelect != null)
            {
                IEnumElement pEnumElement = pGraphicsContainerSelect.SelectedElements;
                IElement pElement = pEnumElement.Next();
                while (pElement != null)
                {
                    if (pElement is IMarkerElement)
                    {
                        IMarkerElement pMarkerElement = (IMarkerElement)pElement;
                        IMarkerSymbol pMarkerSymbol = pMarkerElement.Symbol;
                        pMarkerSymbol.Color = (m_Application.Document as IMxDocument).get_DefaultColor(esriMxDefaultColorTypes.esriMxMarkerColor);
                        pMarkerElement.Symbol = pMarkerSymbol;
                    }
                    pElement = pEnumElement.Next();
                }
            }
            m_ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGraphics, null, null);
        }


        #region ICommand Members

        int ICommand.Bitmap
        {
            get { return 0; }
        }

        string ICommand.Caption
        {
            get { return "DropDownMxColor"; }
        }

        string ICommand.Category
        {
            get { return "颜色设置"; }
        }

        bool ICommand.Checked
        {
            get { return false; }
        }

        bool ICommand.Enabled
        {
            get
            {
                if (m_Application == null)
                    return false; 
                return (m_Application as IFramework).IsSceneCtlActive == false;
            }
        }

        int ICommand.HelpContextID
        {
            get { return 0; }
        }

        string ICommand.HelpFile
        {
            get { return string.Empty; }
        }

        string ICommand.Message
        {
            get { return "DropDownMxColor"; }
        }

        string ICommand.Name
        {
            get { return "DropDownMxColor"; }
        }

        void ICommand.OnClick()
        {

            if (m_Application != null)
            {
                //IColor m_Color = (m_Application.Document as IMxDocument).get_DefaultColor(esriMxDefaultColorTypes.esriMxMarkerColor);
                //this.btnLeft.BackColor = Converter.FromRGBColor(m_Color as IRgbColor);
            }
        }

        void ICommand.OnCreate(object hook)
        {
            m_Application = hook as IApplication;
        }

        string ICommand.Tooltip
        {
            get { return "点颜色设置"; }
        }

        #endregion

    }
}
